﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ADDataPro
{
    public partial class ListDataView : Form
    {
        string _url = string.Empty;
        string[] files;
        public ListDataView(string url)
        {
            InitializeComponent();
            _url = url;
        }

        private void ListDataView_Load(object sender, EventArgs e)
        {
            files = Directory.GetFiles($"{_url}\\..\\ListData", "*.txt");
            files = files.ToList().OrderBy(x => x.Split('_')[2]).ToArray();
            chartControl1.Series["S4"].Points.Clear();
            var index = 0;
            foreach (var file in files)
            {
                using (StreamReader sr = new StreamReader(file))
                {
                    string line = string.Empty;
                    List<Tuple<double, double, double, double>> list = new List<Tuple<double, double, double, double>>();
                    while (!string.IsNullOrEmpty(line = sr.ReadLine()))
                    {
                        var arr = line.Split(',');
                        Tuple<double, double, double, double> tuple = new Tuple<double, double, double, double>(Convert.ToDouble(arr[0]), Convert.ToDouble(arr[1]), Convert.ToDouble(arr[2]), Convert.ToDouble(arr[3]));
                        list.Add(tuple);
                    }

                    var curValue = list.Select(x => x.Item1).Average() + list.Sum(x => x.Item3);
                    chartControl1.Series["S4"].Points.AddPoint(index, curValue/10);
                }
                index++;
            }
        }
    }
}
